﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Threading;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Threading;
using Neurokinetic.NeuroSkyNet.Controller;
using Neurokinetic.NeuroSkyNet.Model;
using Neurokinetic.Electroencephalograph.ViewModel;

namespace Neurokinetic.Electroencephalograph.View
{
    /// <summary>
    /// Interaction logic for Connections.xaml
    /// </summary>
    public partial class ConnectionsView : Window
    {
        private List<ElectroencephalographView> EegWindows = new List<ElectroencephalographView>();


        public List<DateTime> Dates
        {

            get { return (List<DateTime>)GetValue(dates); }
            set { SetValue(dates, value); }

        }
        public static readonly DependencyProperty dates = DependencyProperty.Register("Dates", typeof(List<DateTime>), typeof(ConnectionsView));


        public ConnectionsView()
        {
            Dates = new List<DateTime>();
            for (Int32 i = 0; i < 100; i++)
                Dates.Add(DateTime.Now.AddDays(i));

            try { InitializeComponent(); }
            catch (Exception ex)
            {
                System.IO.StreamWriter sr = new System.IO.StreamWriter("C:\\log.txt", true);
                sr.Write(ex.InnerException.StackTrace.ToCharArray(), 0, ex.InnerException.StackTrace.Length);
            }

        }

        void eegWindow_Closed(object sender, EventArgs e)
        {
            var electroencephalograph = (ElectroencephalographView)sender;
            EegWindows.Remove(electroencephalograph);
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            MindSetController.Mode = MindSetModeType.Standard;
            MindSetController.SearchForMindsets(StatusChanged);
        }

        private void StatusChanged(Object sender, MindSetStatusEventArgs e)
        {
            if (e.Status == MindSetStatusType.Connected)
            {
                ElectroencephalographView eegWindow = new ElectroencephalographView();
                eegWindow.MindSet = e.MindSet;
                eegWindow.Top = 0;
                eegWindow.Left = 0;
                eegWindow.Show();
                eegWindow.Closed += new EventHandler(eegWindow_Closed);
                EegWindows.Add(eegWindow);
            }
        }
    }
}
